#include <QCoreApplication>
#include <QObject>
#include <QDebug>

class Button : public QObject {
    Q_OBJECT

public:
    Button() {}

signals:
    void clicked();  // 定义一个信号

public slots:
    void onClick() {  // 定义响应信号的槽
        emit clicked();  // 发射信号
    }
};

class Application : public QObject {
    Q_OBJECT

public slots:
    void onButtonClicked() {  // 定义用来响应按钮被单击的槽
        qDebug() << "Button was clicked!";
    }
};

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    Button button;
    Application application;

    QObject::connect(&button, &Button::clicked, &application, &Application::onButtonClicked);

    button.onClick();  // 模拟按钮被单击

    return app.exec();  // 启动事件循环
}

#include "main.moc"  // moc 文件的包含（用于包含元对象代码）